<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card style="margin-top: 15px">
      <el-row :gutter="20">
        <el-col :span="8"
          ><el-input placeholder="请输入内容" class="input-with-select" v-model="goodslist.query" @input="searchgoods" @clear="searchgoods">
            <el-button
              on
              slot="append"
              icon="el-icon-search"
              @click="searchgoods"
            ></el-button> </el-input
        ></el-col>
        <el-col :span="16">
          <el-button type="primary" @click="$router.push('/add')">添加商品</el-button>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <template>
        <el-table :data="list" border style="width: 100%; margin-top: 15px">
          <el-table-column type="index" label="#"> </el-table-column>
          <el-table-column prop="goods_name" label="商品名称" width="700">
          </el-table-column>
          <el-table-column prop="goods_price" label="商品价格(元)">
          </el-table-column>
          <el-table-column prop="goods_weight" label="商品重量">
          </el-table-column>
           <el-table-column  prop="goods_number" label="商品数量">
          </el-table-column>
          <el-table-column prop="add_time" label="创建时间">
             <template slot-scope="scope">
              {{scope.row.add_time*1000 | dateFormat}}
            </template>
          </el-table-column>

          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                type="primary"
                icon="el-icon-edit"
                circle
                size="mini"
              ></el-button>
              <el-button
                type="danger"
                icon="el-icon-delete"
                circle
                @click="delgoods(scope.row)"
                size="mini"
              ></el-button>
            </template>
          </el-table-column>
        </el-table> </template
    >
    <el-pagination
      style="margin-top:15px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="goodslist.pagenum"
      :page-sizes="[5, 10, 11, 12]"
      :page-size="goodslist.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </el-card>
    
  </div>
</template>
    </el-card>
  </div>
</template>

<script>
import _ from "lodash";
import { getgoodsApi,getgoodsdelApi } from "@/http/api";
export default {
  data() {
    return {
      list: [],
      goodslist: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
    };
  },
  components: {},
  created() {
    this.getgoodlist();
  },
  mounted() {},
  methods: {
    delgoods(row){
      
       this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            getgoodsdelApi(row.goods_id).then(res=>{
               this.getgoodlist();
            })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
     searchgoods: _.debounce(function () {
      this.getgoodlist();
    }, 300),
    async getgoodlist() {
      var res = await getgoodsApi(this.goodslist);
      console.log(res);
      this.list = res.goods;
      this.total=res.total
    },
     handleSizeChange(val) {
        this.goodslist.pagesize=val
        this.getgoodlist()
      },
      handleCurrentChange(val){
        this.goodslist.pagenum=val
         this.getgoodlist()
      }
  },
  computed: {},
  watch: {},
};
</script>

<style scoped lang='sass'>
</style>
